/*
 * HNode.h
 *
 *  Created on: Apr 30, 2011
 *      Author: Matthew Michelotti
 */

#pragma once

#include <vector>
#include <set>
#include <map>

#include <sfv/csr_matrix.h>

class HNode {

private:
	typedef sfv::csr_matrix<int,float> matrix_t;
	typedef unsigned int uint;

public:
	static void makeNodes(matrix_t& matrix, std::vector<HNode*>& buffer);
	static HNode* formParent(const std::vector<HNode*>& children);
	static void toMatrix(const std::vector<HNode*>& nodes, matrix_t& matrix);
	static void split(std::vector<HNode*>& buffer, int i);

	void print() const;

	inline bool canSplit() const {return !isLeaf;}
	inline int getSize() const {return size;}

private:
	HNode(bool isLeaf) : parent(0), isLeaf(isLeaf), size(isLeaf ? 1 : 0) {}
	void getNeighbors(const std::set<HNode*>& candidates, std::map<HNode*, int>& result,
						const HNode* caller);

	std::vector<HNode*> connections;
	HNode* parent;
	bool isLeaf;
	int size;


	//if isLeaf, connections are normal graph edges between leaves
	//if not isLeaf, connections are child nodes
};
